package sdk.webview.fmc.com.fmcsdk.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import sdk.webview.fmc.com.fmcsdk.R;


/**
 * Created by ydm on 2017/9/14.
 * 登录界面底部的dialog
 */

public class LoginBottomDialog extends Dialog implements View.OnClickListener {
    private ClickListenerInterface clickListenerInterface;
    private TextView tv_msg;
    private String msg;//错误信息
    public LoginBottomDialog(@NonNull Context context, String msg) {
        super(context, R.style.Dialog);
        this.msg = msg;
    }

    public LoginBottomDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
    }

    protected LoginBottomDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_bottom_dialog);
        //设置dialog的属性
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        //dialogWindow.setGravity(Gravity.LEFT | Gravity.TOP);
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.gravity = Gravity.BOTTOM;
        dialogWindow.setAttributes(lp);
        RelativeLayout rl_scan = (RelativeLayout) findViewById(R.id.rl_scan);
        rl_scan.setOnClickListener(this);
        RelativeLayout rl_input = (RelativeLayout) findViewById(R.id.rl_input);
        rl_input.setOnClickListener(this);
        LinearLayout ll_cancel = (LinearLayout) findViewById(R.id.ll_cancel);
        ll_cancel.setOnClickListener(this);
        tv_msg = (TextView) findViewById(R.id.tv_msg);
        tv_msg.setText(msg);
    }

    @Override
    public void onClick(View v) {

        if (v.getId()==R.id.rl_scan){//扫码获得服务器地址
            clickListenerInterface.scan();
        }else if (v.getId()==R.id.rl_input){//手动输入服务器地址
            clickListenerInterface.input();
        }else if (v.getId()==R.id.ll_cancel){//取消
            dismiss();
        }
    }
    public void setClicklistener(ClickListenerInterface clickListenerInterface) {
        this.clickListenerInterface = clickListenerInterface;
    }
    public interface ClickListenerInterface {

        public void scan();

        public void input();
    }
}
